package es.ucm.fdi.bdt.gui;

import java.awt.EventQueue;

import javax.swing.JFrame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.GridBagConstraints;
import java.awt.CardLayout;

import java.awt.FlowLayout;

import javax.swing.SpringLayout;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.JToolBar;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JSeparator;

@SuppressWarnings("serial")
public class GUIInicio extends JFrame{
	protected final int A_X, A_Y, A_WIDTH, A_HEIGHT;
	protected JTextField textFieldBuscar;
	private static final String TITULO="Inicio";

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					new GUIInicio();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public GUIInicio() {
		// Inicializar las coordenadas y dimensiones del avatar
		this.A_X = 22;
		this.A_Y = 40;
		this.A_WIDTH = 50;
		this.A_HEIGHT = 50;
		this.setTitle(TITULO);
		inicializar();
	}
	
	public GUIInicio(String title){
		// Inicializar las coordenadas y dimensiones del avatar
		this.A_X = 22;
		this.A_Y = 40;
		this.A_WIDTH = 50;
		this.A_HEIGHT = 50;
		this.setTitle(title);
		inicializar();
	}

	/**
	 * Initialize the contents of the this.
	 */
	protected void inicializar() {
		// Ajustar las dimensiones de la ventana a la resolución de la pantalla
		Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
	    this.setSize((int) d.getWidth() , (int) d.getHeight());
		//this.setBounds(100, 100, 1116, 1000);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(new GridLayout(0, 3, 0, 0));
		
		JPanel panel_2 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		panel.add(panel_2);
		
		JPanel panel_4 = new JPanel();
		panel_2.add(panel_4);
		JLabel lblLogo = new JLabel();
		panel_4.add(lblLogo);
		Image logo = new ImageIcon("img/Banco-de-tiempo.jpg").getImage();
		lblLogo.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		//lbAvatar.addMouseListener(new OyenteRaton());
		//El 13 y el 35 es la diferencia que hay entre dibujar en una posicion determinada con gráficos y
		//situar un componente de swing
		lblLogo.setBounds(this.A_X - 13, this.A_Y - 35, this.A_WIDTH, this.A_HEIGHT);
		// Ajustar la imagen a las dimensiones del label
		lblLogo.setIcon(new ImageIcon(logo
				.getScaledInstance(this.A_WIDTH - 5, this.A_HEIGHT - 5,
						Image.SCALE_SMOOTH)));
		
		Component horizontalStrut = Box.createHorizontalStrut(20);
		panel_4.add(horizontalStrut);
		
		JMenuBar menuBarServicios = new JMenuBar();
		panel_4.add(menuBarServicios);
		
		JMenu mnServicios = new JMenu("Servicios");
		menuBarServicios.add(mnServicios);
		
		JMenuBar menuBarSolicitudes = new JMenuBar();
		panel_4.add(menuBarSolicitudes);
		
		JMenu mnSolicitudes = new JMenu("Solicitudes");
		menuBarSolicitudes.add(mnSolicitudes);
		
		JMenuItem mntmNewRecibidas = new JMenuItem("Recibidas");
		JMenuItem mntmNewEnviadas = new JMenuItem("Enviadas");
		mnSolicitudes.add(mntmNewRecibidas);
		mnSolicitudes.add(mntmNewEnviadas);
		
		JMenuBar menuBarUsuarios = new JMenuBar();
		panel_4.add(menuBarUsuarios);
		
		JMenu mnUsuarios = new JMenu("Usuarios");
		menuBarUsuarios.add(mnUsuarios);
		
		JPanel panel_1 = new JPanel();
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		textFieldBuscar = new JTextField();
		textFieldBuscar.setBounds(92, 22, 279, 19);
		textFieldBuscar.setHorizontalAlignment(SwingConstants.LEFT);
		textFieldBuscar.setColumns(25);
		panel_1.add(textFieldBuscar);
		
		JLabel lblBuscar = new JLabel("Buscar:");
		lblBuscar.setLabelFor(textFieldBuscar);
		lblBuscar.setBounds(36, 25, 46, 14);
		panel_1.add(lblBuscar);
		
		JPanel panel_3 = new JPanel();
		panel.add(panel_3);
		panel_3.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_5 = new JPanel();
		panel_3.add(panel_5);
		panel_5.setLayout(new GridLayout(2, 2, 0, 0));
		
		JLabel lblNombre = new JLabel("Pepe");
		panel_5.add(lblNombre);
		lblNombre.setHorizontalAlignment(SwingConstants.CENTER);
		
		JLabel lblHoras = new JLabel("3 horas");
		panel_5.add(lblHoras);
		lblHoras.setVerticalAlignment(SwingConstants.TOP);
		lblHoras.setHorizontalAlignment(SwingConstants.CENTER);
		
		JPanel panel_6 = new JPanel();
		panel_3.add(panel_6, BorderLayout.EAST);
		Image config = new ImageIcon("img/config.png").getImage();
		JLabel lblConfig = new JLabel();
		lblConfig.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_6.add(lblConfig);
		lblConfig.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		//lbAvatar.addMouseListener(new OyenteRaton());
		//El 13 y el 35 es la diferencia que hay entre dibujar en una posicion determinada con gráficos y
		//situar un componente de swing
		lblConfig.setBounds(this.A_X - 13, this.A_Y - 35, this.A_WIDTH, this.A_HEIGHT);
		// Ajustar la imagen a las dimensiones del label
		lblConfig.setIcon(new ImageIcon(config
				.getScaledInstance(this.A_WIDTH - 5, this.A_HEIGHT - 5,
						Image.SCALE_SMOOTH)));
		
		Image ayuda = new ImageIcon("img/ayuda.png").getImage();
		JLabel lblAyuda = new JLabel();
		lblAyuda.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_6.add(lblAyuda);
		lblAyuda.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		lblAyuda.setBounds(this.A_X - 13, this.A_Y - 35, this.A_WIDTH, this.A_HEIGHT);
		lblAyuda.setIcon(new ImageIcon(ayuda
				.getScaledInstance(this.A_WIDTH - 5, this.A_HEIGHT - 5,
						Image.SCALE_SMOOTH)));
		
		JSeparator separator = new JSeparator();
		panel_6.add(separator);
		
		Component horizontalGlue = Box.createHorizontalGlue();
		panel_6.add(horizontalGlue);
		
		this.setVisible(true);
	}
}
